package com.qdxwx.manage.controller.monitor;

import com.qdxwx.common.json.AjaxResult;
import com.qdxwx.common.page.PageRequest;
import com.qdxwx.common.page.TableDataInfo;
import com.qdxwx.data.service.operLog.OperLogService;
import com.qdxwx.manage.annotation.Log;
import com.qdxwx.common.annotation.Permissions;
import com.qdxwx.manage.controller.BaseController;
import com.qdxwx.models.enums.BusinessType;
import com.qdxwx.models.operLog.OperLog;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 操作日志记录
 * Qdx NetSchool Platform
 * @author qdxwx
 * @updateTime 2022/5/25
 * @description
 */
@Controller
@RequestMapping("/operlog")
public class OperlogController extends BaseController
{
    private String prefix = "operlog";

    @Autowired
    private OperLogService operLogService;

    @Permissions("operlog:list")
    @GetMapping("/list.html")
    public String operlog()
    {
        return prefix + "/operlog";
    }

    @Permissions("monitor:operlog:list")
    @PostMapping("/list.json")
    @ResponseBody
    public TableDataInfo list(HttpServletRequest request, OperLog operLog)
    {
        List<OperLog> list = operLogService.getList(operLog, PageRequest.form(request));
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(0);
        rspData.setRows(list);
        rspData.setTotal(operLogService.count(operLog));
        return rspData;
    }

    @Permissions("monitor:operlog:remove")
    @PostMapping("/remove.json")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(operLogService.deleteByIds(ids));
    }

    @Permissions("monitor:operlog:detail")
    @GetMapping("/detail/{operId}")
    public String detail(@PathVariable("operId") Long operId, ModelMap mmap)
    {
        mmap.put("operLog", operLogService.get(operId));
        return prefix + "/detail";
    }
    
    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @Permissions("monitor:operlog:remove")
    @PostMapping("/clean.json")
    @ResponseBody
    public AjaxResult clean()
    {
        operLogService.clean();
        return success();
    }
}
